package com.feilong.edgeAI.ui;

import android.os.Build;
import android.os.Bundle;
import android.webkit.WebSettings;

import androidx.annotation.Nullable;
import androidx.annotation.RequiresApi;

import com.aiibt.common.core.WDActivity;
import com.aiibt.common.util.Constant;
import com.alibaba.android.arouter.facade.annotation.Autowired;
import com.alibaba.android.arouter.facade.annotation.Route;
import com.feilong.edgeAI.R;
import com.feilong.edgeAI.databinding.ActivityHelpBinding;
import com.feilong.edgeAI.databinding.ActivityWebBinding;
import com.feilong.edgeAI.model.FeilongRespone;
import com.feilong.edgeAI.vm.WebViewModel;

/**
 * Created by【仿脑科技】
 * 帮助页面，以图片方式展示
 *
 * @Author: potato
 * @CreateDate: 2023/12/20 14:56
 */

@Route(path = Constant.ACTIVITY_URL_WEB)
public class WebActivity extends WDActivity<WebViewModel, ActivityWebBinding> {
    @Autowired
    public FeilongRespone feilongRespone;
    private static final String TAG = "WebActivity";

    @RequiresApi(api = Build.VERSION_CODES.N)
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

    }

    @Override
    protected int getLayoutId() {
        return R.layout.activity_web;
    }

    @Override
    protected void initView(Bundle savedInstanceState) {
        if (feilongRespone == null) {
            return;
        }
        if (!feilongRespone.getUrl().isEmpty() && feilongRespone.getUrl().length() > 0) {
            binding.title.setText(feilongRespone.getText());
            WebSettings webSettings = binding.webView.getSettings();




//            //设置支持js
//            webSettings.setJavaScriptEnabled(true);
//            //设置适应屏幕
//            webSettings.setUseWideViewPort(true); //将图片调整到适合webview的大小
//            webSettings.setLoadWithOverviewMode(true); // 缩放至屏幕的大小
//            webSettings.setPluginState(WebSettings.PluginState.ON);//设置是否支持插件
//            webSettings.setSupportZoom(true); //支持缩放
//            webSettings.setBuiltInZoomControls(true);
//            webSettings.setDisplayZoomControls(false); //隐藏原生的缩放控件
//            //设置存储模式
//            webSettings.setCacheMode(WebSettings.LOAD_NO_CACHE);
//            webSettings.setAllowFileAccess(true);
//            //setDomStorageEnabled解决了webview白屏问题  设置支持DomStorage
//            webSettings.setDomStorageEnabled(true);
//            //设置支持本地存储
//            webSettings.setDatabaseEnabled(true);
//            //设置缓存
////            webSettings.setAppCacheEnabled(true);
//            webSettings.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.NARROW_COLUMNS);
//            webSettings.setJavaScriptCanOpenWindowsAutomatically(true);//支持通过JS打开新窗口
//            webSettings.setLoadsImagesAutomatically(true); //支持自动加载图片
//            webSettings.setDefaultTextEncodingName("utf-8");


            webSettings.setJavaScriptEnabled(true);
            webSettings.setTextZoom(100);
            if(feilongRespone.getText().equals("用户隐私协议")){
                binding.webView.loadUrl(feilongRespone.getUrl());
            }else{
                binding.webView.loadUrl("http://175.178.26.152:8181" + feilongRespone.getUrl());
            }

        }
    }


    @Override
    protected void onDestroy() {
        super.onDestroy();
    }
}
